package servlet.shop;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import beans.Info;
import beans.Shop;
import service.ShopService;

@WebServlet("/ShopServlet")
public class ShopServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public ShopServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ShopService service = new ShopService();
		
		String page = request.getParameter("page"); // 第几页
		if (page == null)
			page = "1";
		Info<Shop> info = service.getShop(page);
		
		request.setAttribute("shops", info.list);
		request.setAttribute("page", page);
		request.setAttribute("count", info.count);
		request.getRequestDispatcher("/admin/shop.jsp").forward(request, response);
	}

}
